package set;

import java.util.ArrayList;

import binaryTree.bst.CandyBinarySearchTree_v2;
import util.FileOperation;

public class CandyBSTSet<E extends Comparable<E>> implements CandySet<E> {
    private CandyBinarySearchTree_v2<E> bst;
    
    public CandyBSTSet() {
        this.bst = new CandyBinarySearchTree_v2<>();
    }

    @Override
    public void add(E e) {
        bst.add(e);
    }

    @Override
    public void remove(E e) {
        bst.remove(e);
    }

    @Override
    public boolean contains(E e) {
        return bst.contains(e);
    }

    @Override
    public int getSize() {
        return bst.size();
    }

    @Override
    public boolean isEmpty() {
        return bst.isEmpty();
    }
    
    public static void main(String[] args) {
        wordCount("傲慢与偏见英文原版书词汇量统计：", "testData/pride-and-prejudice.txt");
        wordCount("双城记原版书词汇量统计：", "testData/a-tale-of-two-cities.txt");
    }
    
    // 统计词汇量
    private static void wordCount(String title, String filePath) {
        System.out.println("-------------" + title + "----------------");
        ArrayList<String> words1 = new ArrayList<>();
        FileOperation.readFile(filePath, words1);
        System.out.println("单词总数：" + words1.size());
        CandyBSTSet<String> set = new CandyBSTSet<>();
        for(String word : words1) {
            set.add(word);
        }
        System.out.println("不同单词数量：" + set.getSize());
    }
}
